//
//  CustomCell.m
//  Footer
//
//  Created by leotao on 16/12/17.
//  Copyright © 2016年 leotao. All rights reserved.
//

#import "CustomCell.h"
#import "Masonry.h"

#define RGB(r,g,b) [UIColor colorWithRed: r / 255.0 green: g / 255.0 blue: b / 255.0 alpha:1.0]

@interface CustomCell ()

@property (strong, nonatomic) UIImageView *iconImageView;
@property (strong, nonatomic) UILabel *statusLabel;
@property (strong, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) UILabel *answerLabel;

@end

@implementation CustomCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIView *container = [UIView new];
        self.contentView.backgroundColor = RGB(242, 244, 247);
        container.backgroundColor = [UIColor whiteColor];
        
        UIImageView *imageView = [UIImageView new];
        imageView.layer.cornerRadius = 13;
        imageView.clipsToBounds = YES;
        [container addSubview:imageView];
        
        UILabel *stautsLabel = [UILabel new];
        stautsLabel.textColor = RGB(145, 158, 165);
        stautsLabel.font = [UIFont systemFontOfSize:15];
        [container addSubview:stautsLabel];
        
        UILabel *titleLabel = [UILabel new];
        titleLabel.textColor = [UIColor blackColor];
        titleLabel.font = [UIFont boldSystemFontOfSize:18];
        titleLabel.numberOfLines = 0;
        [container addSubview:titleLabel];
        
        UILabel *answerLabel = [UILabel new];
        answerLabel.textColor = stautsLabel.textColor;
        answerLabel.font = stautsLabel.font;
        [container addSubview:answerLabel];
        
        UIView *line = [UIView new];
        line.backgroundColor = RGB(205, 207, 209);
        [container addSubview:line];
        
        [self.contentView addSubview:container];
        
        self.iconImageView = imageView;
        self.titleLabel = titleLabel;
        self.statusLabel = stautsLabel;
        self.answerLabel = answerLabel;
        
        [container mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(self.contentView);
            make.top.equalTo(self.contentView).offset(10);
        }];
        
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.equalTo(container).offset(20);
            make.size.mas_equalTo(CGSizeMake(26, 26));
        }];
        
        [stautsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(imageView.mas_right).offset(10);
            make.right.lessThanOrEqualTo(container).offset(-20);
            make.centerY.equalTo(imageView);
        }];
        
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(imageView.mas_bottom).offset(15);
            make.left.equalTo(imageView);
            make.right.equalTo(container).offset(-20);
        }];
        
        [answerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(titleLabel.mas_bottom).offset(20);
            make.left.right.equalTo(titleLabel);
            make.bottom.equalTo(container).offset(-15);
        }];
        
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(container);
            make.height.equalTo(@(2 / [UIScreen mainScreen].scale));
        }];
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    return self;
}

- (void)configureCell:(NSInteger)num
{
    UIImage *image;
    NSString *status;
    NSString *title;
    NSString *answer;
    if (num % 2 == 0) {
        image   = [UIImage imageNamed:@"icon1.jpeg"];
        status  = @"梁边妖关注了问题";
        title   = @"如何看待中国军舰在苏比克湾薅了一艘美国海军水下无人艇?";
        answer  = @"164回答 · 1.2K关注 · 关注问题";
    } else {
        image = [UIImage imageNamed:@"icon2.jpeg"];
        status  = @"闲谈后赞同该回答";
        title   = @"写小说时，一有人在后边看，精神就尴尬，紧张，没有思绪，如何克服？";
        answer  = @"34赞同 · 18评论 · 关注问题";
    }
    
    self.iconImageView.image = image;
    self.statusLabel.text = status;
    self.titleLabel.text = title;
    self.answerLabel.text = answer;
}

@end
